package com.qfedu.mtl.controller;

import com.qfedu.mtl.util.web.annotation.Controller;
import com.qfedu.mtl.util.web.annotation.RequestMapping;
import com.wf.captcha.GifCaptcha;
import com.wf.captcha.base.Captcha;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @version v1.0
 * @Date 2023/9/25 14:24
 * @Author DARKER
 * @Email 1402216045@qq.com
 */
@Controller
@RequestMapping("/common")
public class CaptchaController {
    @RequestMapping("/captcha")
    public void createCaptcha(HttpServletRequest rep, HttpServletResponse resp) throws IOException {
        Captcha captcha = new GifCaptcha(120,30,4);
        //获得真实的图片的内容字符串
        String realCode = captcha.text();
        //保存到session域
        HttpSession session = rep.getSession();
        session.setAttribute("captcha_login",realCode);
        //把验证码输出到客户端
        System.out.println(realCode);
        captcha.out(resp.getOutputStream());

    }
}
